package main

import (
	"fmt"
	"time"
)

func main() {
	var chal = make(chan int)
	go process(chal)

	for {
		v, ok := <-chal
		if !ok {
			fmt.Println("chal is closed.")
			break
		}
		fmt.Println("received ", v, ok)
	}
}

// 异步处理
func process(chal chan<- int) {
	for i := 0; i < 5; i++ {
		time.Sleep(time.Second)
		chal <- i
	}
	close(chal)
}
